PHP efficiency question [closed]
Posted
by
Ron
on Pro Webmasters
See other posts from Pro Webmasters
or by Ron
Published on 2011-03-12T01:34:49Z
Indexed on
2011/03/12
8:17 UTC
Read the original article
Hit count: 212
php
Hello everyone.
I am working on website and I am trying to make it fast as much as possible - especially the small things that can make my site a little bit quicker.
So, my to my question - I got loop that run 5 times and in each time it echo something, If I'll make variable and the loop will add the text I want to echo into the variable and just in the end I'll echo the variable - will it be faster?
loop 1 (with the echo inside the loop)
for ($i = 0;$i < 5;$i++)
{
echo "test";
}
loop 2 (with the echo outside [when the loop finish])
$echostr = "";
for ($i = 0;$i < 5;$i++)
{
$echostr .= "test";
}
echo $echostr;
I know that loop 2 will increase a bit the file size and therefore the user will have to download more bytes but If I got huge loop will it be better to use second loop or not?
Thanks.
© Pro Webmasters or respective owner